package com.jt.www.model.reps;


import com.jt.www.enums.BaseEnum;
import com.jt.www.enums.ResultEnum;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.util.StringUtils;


/**
 * 描述：
 * 类名称：统一返回的消息包装类
 * 作者： wangyang
 * 版本：1.0
 * 修改：
 * 创建日期：
 * 版权：江泰保险经纪股份有限公司
 */

public class RemoteResultDTO<T> {

    @ApiModelProperty(value = "错误码:200/0000{成功} 401{参数错误} 400{服务器内部错误}")
    private Object code;

    @ApiModelProperty(value = "提示信息")
    private String msg;

    @ApiModelProperty(value = "结果总记录数")
    private Long total;
    @ApiModelProperty(value = "具体内容")
    private T data;


    public RemoteResultDTO(BaseEnum resultEnum) {
        super();
        this.code = resultEnum.getCode();
        this.msg = resultEnum.getMsg();
    }

    public RemoteResultDTO(BaseEnum resultEnum, String msg) {
        super();
        this.code = resultEnum.getCode();
        if (StringUtils.isEmpty(msg)) {
            this.msg = resultEnum.getMsg();
        } else {
            this.msg = msg;
        }
    }

    public RemoteResultDTO(BaseEnum resultEnum, T data, Long total) {
        super();
        this.code = resultEnum.getCode();
        this.msg = resultEnum.getMsg();
        this.data = data;
        this.total = total;
    }


    public RemoteResultDTO() {
        super();
    }

    public RemoteResultDTO(String msg) {
        super();
        this.msg = msg;
    }

    public static RemoteResultDTO createDefaultResult() {
        return new RemoteResultDTO(ResultEnum.SUCCESS);
    }

    public static RemoteResultDTO createDefaultResultFail(ResultEnum resultEnum, String msg) {
        return new RemoteResultDTO(resultEnum == null ? ResultEnum.SERVER_ERROR : resultEnum, msg);
    }

    public static RemoteResultDTO createDefaultResultFail(String msg) {
        return createDefaultResultFail(null, msg);
    }

    public static RemoteResultDTO createDefaultResultFail() {
        return createDefaultResultFail(null, null);
    }

    public static RemoteResultDTO createDefaultResultFail(ResultEnum resultEnum) {
        return createDefaultResultFail(resultEnum, null);
    }

    public Object getCode() {
        return code;
    }

    public void setCode(Object code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Long getTotal() {
        return total;
    }

    public void setTotal(Long total) {
        this.total = total;
    }

    public T getData() {
        return data;
    }

    public RemoteResultDTO setData(T data) {
        this.data = data;
        return this;
    }
}
